/**
 * 多态：所谓的多态是指在继承关系或者实现关系中
 * 实现同一个父类方法，表现出不同的结果称为多态
 * 
 * 多态：在定义方法的时候，不要传递具体的子类，而要传递抽象
 * 步骤
 * 1、编写父类
 * 2、编写子类
 * 3、在引用关系中的方法定义的时候规则传递的是父类
 * 4、在使用的时候传递是具体的子类
 * 
 * 好处：可以扩展程序，让程序具有扩展性和可维护性
 */

class Pet{
    private name:string=""
    public health:number=50
    public love:number=10
    constructor(name:string){
        this.name=name
    }
    show(){
       return `昵称:${this.name}\n：健康值:${this.health}\n:亲密度:${this.love}`
        
    }
    eat(){
        console.log('动物吃食');
    }
}
class DogType extends Pet{
    private type:string=""
    constructor(name:string,type:string){
        super(name)
        this.type=type
    }
    show(){
       return `${super.show()}\n类型:${this.type}`
    }
    eat(): void {
        console.log('狗吃狗粮');
        //使用this访问
        this.health=this.health+5
        this.love=this.love+1
    }
    catchFly(){
        console.log('够玩接分盘游戏');
        this.health=this.health-2
        this.love=this.love+10
    }
}
class Cat extends Pet{
    private color:string=""
    constructor(name:string,color:string){
      super(name)
      this.color=color
    }
    show(){
        return `${super.show()}\n颜色:${this.color}` 
    }
    eat(): void {
        console.log('猫吃猫粮');
        this.health=this.health+10
        this.love=this.love+20
    }
    catchBall(){
        console.log('猫玩小球游戏');
        this.health=this.health-10  
        this.love=this.love+20
    }
}

class Master{
    private name:string=""
    constructor(name:string){
        this.name=name
    }
    introduce(){
        return `我叫${this.name}`
    }
    adopt(pet:Pet){
        pet.eat()
        if(pet instanceof DogType){
            pet.catchFly()
        }else if(pet instanceof Cat){
            pet.catchBall()
        }
    }
   
}

let zjz=new Master('翟吉喆')
console.log(zjz.introduce());

console.log('==========领养列表1--领养狗===================');
let wz=new DogType("旺仔","拉布拉多")
console.log(wz.show());
console.log('---------领养前后--------------');
zjz.adopt(wz)
console.log(wz.show());
console.log('==========领养列表2--领养猫===================');
let xb=new Cat("小白","白色")
console.log(xb.show());
zjz.adopt(xb)
console.log(xb.show());








